package com.aifund.common.dao;

import com.aifund.common.entity.AiUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserDao extends JpaRepository<AiUser,Long>, JpaSpecificationExecutor<AiUser> {




    /**
     * 获取今日注册人数
     * @return
     */
    @Query(nativeQuery = true,value = "select count(*) from ai_user where is_del = 0 and TO_DAYS(create_time) = TO_DAYS(now())")
    int getTodayRegister();

    /**
     * 通过手机号和密码获取用户实例
     * @param phone
     * @param pwd
     * @return
     */
    AiUser getByPhoneAndAiPassword(String phone, String pwd);

    /**
     * 根据邮箱和密码获取用户实例
     * @param email
     * @param password
     * @return
     */
    AiUser getByEmailAndAiPassword(String email, String password);

    /**
     * 根据手机号获取用户
     * @param phone
     * @return
     */
    AiUser getByPhone(String phone);

    /**
     * 根据ID获取用户
     * @param id
     * @return
     */
    AiUser getById(Long id);

    /**
     * 根据邀请码获取用户
     * @param code
     * @return
     */
    AiUser getByInvitationCode(String code);

    /**
     * 获取某个类型的用户组
     * @param index
     * @return
     */
    List<AiUser> getByUserIndex(int index);

    /**
     * 分页查找用户
     * @param specification
     * @param pageable
     * @return
     */
    @Override
    Page<AiUser> findAll(Specification<AiUser> specification, Pageable pageable);

    /**
     * 分页用户
     * @param pageable
     * @return
     */
    @Override
    Page<AiUser> findAll(Pageable pageable);



}
